package com.tjetc.view.adminview;

import com.tjetc.proxy.CilentProxy;
import com.tjetc.view.studentview.StudentMainView;
import com.zhiyun.domain.AdminNotice;
import com.zhiyun.service.AdminNoticeService;
import com.zhiyun.service.AdminService;
import com.zhiyun.vo.AppData;
import com.zhiyun.vo.Result;

import java.util.Date;
import java.util.Scanner;

public class AdminsMainView {

    AdminService adminService=CilentProxy.getProxyInstance(AdminService.class);
    AdminNoticeService adminNoticeService= CilentProxy.getProxyInstance(AdminNoticeService.class);
    Scanner scanner=new Scanner(System.in);
    public void start() {
        Integer permission = AppData.admin.getPermission();
        while (true){
            System.out.println("~~~~~~~~~管理员~~~~~~~~~");
            System.out.println("1. 发布公告");
            System.out.println("2. 查看留言");
            System.out.println("3. 用户管理");
            System.out.println("4. 用户类型管理");
            System.out.println("5. 题目类型管理");
            if (permission==1){
                System.out.println("6. 管理员管理");
            }
            System.out.println("0. 退出");
            int i = scanner.nextInt();
            switch (i){
                case 1:
                    adminNotice();
                    break;
                case 2:
                    new Admins_Mails().start();
                    break;
                case 3:
                    new Admin_User().start();
                    break;
                case 4:
                    new Admins_UserClass().start();
                    break;
                case 5:
                    new Admins_Exams().start();
                    break;
                case 6:
                    new Admin_Manage().start();
                    break;
                case 0:

                    return;
                default:
                    break;
            }
        }
    }

    private void adminNotice() {
        while (true){
            System.out.println("请输入想要发布的公告内容");
            String scanners = scanner.next();
            AdminNotice adminNotice = new AdminNotice(null, scanners, new Date(), AppData.admin.getId());
            Result result = adminNoticeService.addAdminNotice(adminNotice);
            if (result.getCode()==200){
                System.out.println(result.getMsg());
            }else {
                System.out.println(result.getMsg());
            }
            System.out.println("是否继续发布公告(Y/N)");
            String next = scanner.next();
            if (next.equals("Y")){

            }else {
                break;
            }
        }
    }
}
